package cn.cj.erp.modules.system.controller;

import cn.cj.erp.bo.system.SysNoticeUserReadBo;
import cn.cj.erp.common.security.annotation.Log;
import cn.cj.erp.common.enums.LogBusinessTypeEnum;
import cn.cj.erp.common.Page;
import cn.cj.erp.common.http.Result;
import cn.cj.erp.common.utils.id.IdGenerator;
import cn.cj.erp.modules.common.controller.AbstractController;
import cn.cj.erp.service.system.SysNoticeUserReadService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.security.access.prepost.PreAuthorize;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

/**
 * 通知公告用户阅读表
 * @author chenjian
 */
@Slf4j
@Validated
@RestController
@RequestMapping("system/sysnoticeuserread")
public class SysNoticeUserReadController extends AbstractController {
    @Resource
    private SysNoticeUserReadService sysNoticeUserReadService;

    @PostMapping("/list")
    @PreAuthorize("@ss.hasPerm('system:sysnoticeuserread:list')")
    public Result<Page<SysNoticeUserReadBo>> list(@RequestBody SysNoticeUserReadBo params) {
        return Result.query(sysNoticeUserReadService.queryPage(params));
    }

    @GetMapping("/info/{id}")
    @PreAuthorize("@ss.hasPerm('system:sysnoticeuserread:query')")
    public Result<SysNoticeUserReadBo> info(@PathVariable("id") Long id) {
        return Result.query(sysNoticeUserReadService.getById(id));
    }

    @PostMapping("/save")
    @PreAuthorize("@ss.hasPerm('system:sysnoticeuserread:add')")
    @Log(title = "通知公告用户阅读表", businessType = LogBusinessTypeEnum.INSERT)
    public Result<Boolean> save(@Valid @RequestBody SysNoticeUserReadBo sysNoticeUserRead) {
        sysNoticeUserRead.setId(IdGenerator.generateId());
        return Result.save(sysNoticeUserReadService.save(sysNoticeUserRead));
    }

    @PostMapping("/update")
    @PreAuthorize("@ss.hasPerm('system:sysnoticeuserread:edit')")
    @Log(title = "通知公告用户阅读表", businessType = LogBusinessTypeEnum.UPDATE)
    public Result<Boolean> update(@Valid @RequestBody SysNoticeUserReadBo sysNoticeUserRead) {
        return Result.update(sysNoticeUserReadService.updateById(sysNoticeUserRead));
    }

    @PostMapping("/delete")
    @PreAuthorize("@ss.hasPerm('system:sysnoticeuserread:remove')")
    @Log(title = "通知公告用户阅读表", businessType = LogBusinessTypeEnum.DELETE)
    public Result<Boolean> delete(@RequestBody List<Long> ids) {
        return Result.remove(sysNoticeUserReadService.removeByIds(ids));
    }

}
